package com.sxj.corejava.code08_常用类.内部类;

/**
 * @author 石小俊
 */
public class Test02_局部内部类 {

    public static void main(String[] args) {
        // 在外部无法实例化局部内部类对象
        OuterTwo outerTwo = new OuterTwo();
        outerTwo.show();
    }

}

class OuterTwo {
    private String name = "outer";
    private int age = 20;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void test() {

    }

    public void show() {
        String gender = "男";
        class InnerTwo {
            private String name = "inner";
            private String phone = "13812345678";

            public void print() {
                System.out.println("内部类name:" + name);
                OuterTwo outerTwo = new OuterTwo();
                System.out.println("外部类name:" + outerTwo.name);
                System.out.println("外部类name:" + OuterTwo.this.name);
                System.out.println(age);
                System.out.println(phone);
                // 访问内部类所在的外部类方法中的局部变量
                // 此时的局部变量必须是被final修饰的
                // 在JDK8之前必须手动添加final修饰符,JDK8之后默认自动添加final修饰符
                System.out.println(gender);
                // 由于变量被final修饰,因此,变量的值不能修改
                // 一旦修改,final失效,报错
                // gender = "女";
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public String getPhone() {
                return phone;
            }

            public void setPhone(String phone) {
                this.phone = phone;
            }
        }
        System.out.println("*******************外部类方法*******************");
        // 只能在局部内部类所在的外部类方法中实例化内部类
        InnerTwo innerTwo = new InnerTwo();
        innerTwo.print();
        System.out.println(name);
        System.out.println(age);
        System.out.println(innerTwo.name);
        System.out.println(innerTwo.phone);
    }
}